/*
 * Copyright (C) 2010-2011 dppc.org
 * All rights reserved.
 */
package com.seemsea.web.app.qihoo;

/**
 * 该类是所有工作流程的父类（等等功能说明）
 * 
 * @author chirowong
 * @version 1.0 2011-6-13
 * @since 1.0
 */
public class Change {
	String in;
	String out = "";

	public Change() {

	}

	public Change(String in) {
		this.in = in;
	}

	public void setIn(String in) {
		this.in = in;
	}

	public String change() {
		int lengthOfP1 = (in.indexOf(".") != -1) ? in.indexOf(".") : in.length();// 整数部分//;
		int lengthOfP2 = (in.indexOf(".") != -1) ? in.length() - lengthOfP1 - 1: in.length() - lengthOfP1;// 小数部分//;
		if (lengthOfP2 > 2) {
			in = in.substring(0, in.indexOf(".") + 3);
		}// 取两位小数//
		int p1 = 0;
		int p2 = 0;

		if (in.indexOf(".") != -1 && in.indexOf(".") != in.length() - 1) {
			p1 = Integer.parseInt(in.substring(0, in.indexOf(".")));

			p2 = Integer.parseInt(in.substring(in.indexOf(".") + 1, in.length()));
			// 取两位小数//
		}

		else if (in.indexOf(".") == in.length() - 1) {
			p1 = Integer.parseInt(in.substring(0, in.indexOf(".")));
		}

		else {
			p1 = Integer.parseInt(in);
		}

		if (p2 < 10 && lengthOfP2 == 1) {
			p2 = p2 * 10;
		}
		// 取两位数//

		if (lengthOfP1 >= 10) {
			return "Too much money.";
		}

		for (int i = lengthOfP1; i > 0; i--) {

			int temp = (p1 / ((int) Math.pow(10, i - 1)));
			out += temp == 0?value3(temp):value3(temp) + value1(i);
			p1 = p1 % (int) Math.pow(10, i - 1);

		}

		for (int i = 2; i > 0; i--) {
			int temp = (p2 / ((int) Math.pow(10, i - 1)));
			out += value3(temp) + value2(i);
			p2 = p2 % (int) Math.pow(10, i - 1);
		}

		String output = out;

		out = "";

		return output;
	}

	public static String value1(int num) {

		switch (num) {
		case 1:
			return "元";

		case 2:
			return "十";

		case 3:
			return "百";

		case 4:
			return "千";

		case 5:
			return "万";

		case 6:
			return "十万";

		case 7:
			return "百万";

		case 8:
			return "千万";

		case 9:
			return "亿";

		default:
			return null;
		}

	}// 转为中文符号//

	public static String value2(int num) {

		switch (num) {
		case 2:
			return "角";

		case 1:
			return "分";

		default:
			return null;
		}

	}// 转为中文符号//

	public static String value3(int num) {
		String s = "零壹贰叁肆伍陆柒捌玖";

		return s.charAt(num) + "";
	}// 转大写//
}
